﻿namespace Devonline.Entity;

/// <summary>
/// 销售订单
/// 数据规模: 万
/// </summary>
[Table("sale_order"), DisplayName("销售订单")]
public class SaleOrder : SaleOrder<string>, IEntitySet, IEntitySetWithCreate, IEntitySetWithCreateAndUpdate
{
    /// <summary>
    /// 下单客户
    /// </summary>
    public virtual Customer? Customer { get; set; }
    /// <summary>
    /// 销售订单明细
    /// </summary>
    public virtual ICollection<SaleOrderDetail>? Details { get; set; }
    /// <summary>
    /// 销售订单支付记录
    /// </summary>
    public virtual ICollection<SaleOrderPaymentRecord>? PaymentRecords { get; set; }
}

/// <summary>
/// 销售订单
/// 数据规模: 万
/// </summary>
[Table("sale_order"), DisplayName("销售订单")]
public abstract class SaleOrder<TKey> : EntitySetWithCreateAndUpdate<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey>, IEntitySetWithCreateAndUpdate<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 客户编号
    /// </summary>
    [Column("customer_id"), DisplayName("客户编号"), Required, MaxLength(36), Excel]
    public virtual TKey CustomerId { get; set; } = default!;
    /// <summary>
    /// 订单号
    /// </summary>
    [Column("order_number"), Required, MaxLength(36), DisplayName("订单号")]
    public virtual string OrderNumber { get; set; } = null!;
    /// <summary>
    /// 下单时间
    /// </summary>
    [Column("order_time"), DisplayName("下单时间"), Excel]
    public virtual DateTime OrderTime { get; set; }
    /// <summary>
    /// 订单金额
    /// </summary>
    [Column("amount", TypeName = "decimal(18,2)"), DisplayName("订单金额"), Excel]
    public virtual decimal Amount { get; set; }
    /// <summary>
    /// 支付方式
    /// </summary>
    [Column("payment_type", TypeName = "varchar(16)"), DisplayName("支付方式"), DefaultValue(PaymentType.WeChatPay), Excel]
    public virtual PaymentType PaymentType { get; set; }
    /// <summary>
    /// 总重
    /// </summary>
    [Column("weight", TypeName = "decimal(18,2)"), DisplayName("总重"), Excel]
    public virtual decimal? Weight { get; set; }
    /// <summary>
    /// 运费
    /// </summary>
    [Column("freight", TypeName = "decimal(18,2)"), DisplayName("运费"), Excel]
    public virtual decimal? Freight { get; set; }
    /// <summary>
    /// 运单号
    /// </summary>
    [Column("tracking_number"), MaxLength(36), DisplayName("运单号")]
    public virtual string? TrackingNumber { get; set; }
    /// <summary>
    /// 发货时间
    /// </summary>
    [Column("shipping_time"), DisplayName("发货时间"), Excel]
    public virtual DateTime? ShippingTime { get; set; }
    /// <summary>
    /// 到货时间
    /// </summary>
    [Column("deliver_time"), DisplayName("到货时间"), Excel]
    public virtual DateTime? DeliverTime { get; set; }
    /// <summary>
    /// 备注说明
    /// </summary>
    [Column("description"), DisplayName("备注说明"), MaxLength(1024), Excel]
    public override string? Description { get; set; }
}

/// <summary>
/// 订单明细
/// </summary>
[Table("sale_order_detail"), DisplayName("订单明细")]
public class SaleOrderDetail : SaleOrderDetail<string>, IEntitySet, IEntitySetWithCreate
{
    /// <summary>
    /// 订单
    /// </summary>
    public virtual SaleOrder? Order { get; set; }
    /// <summary>
    /// 货品
    /// </summary>
    public virtual Product? Product { get; set; }
}

/// <summary>
/// 订单明细
/// </summary>
[Table("sale_order_detail"), DisplayName("订单明细")]
public abstract class SaleOrderDetail<TKey> : EntitySetWithCreate<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 订单编号
    /// </summary>
    [Column("order_id"), Required, MaxLength(36), DisplayName("订单编号")]
    public virtual TKey OrderId { get; set; } = default!;
    /// <summary>
    /// 货品编号
    /// </summary>
    [Column("product_id"), Required, MaxLength(36), DisplayName("货品编号"), Excel]
    public virtual TKey ProductId { get; set; } = default!;
    /// <summary>
    /// 单价
    /// </summary>
    [Column("price", TypeName = "decimal(18,2)"), DisplayName("单价"), Excel]
    public virtual decimal Price { get; set; }
    /// <summary>
    /// 数量
    /// </summary>
    [Column("count", TypeName = "decimal(12,0)"), DisplayName("数量"), Excel]
    public virtual decimal Count { get; set; }
}

/// <summary>
/// 销售订单支付记录
/// </summary>
[Table("sale_order_payment_record"), DisplayName("销售订单支付记录")]
public class SaleOrderPaymentRecord : SaleOrderPaymentRecord<string>, IEntitySet, IEntitySetWithCreate
{
    /// <summary>
    /// 交易账户
    /// </summary>
    public virtual Account? Account { get; set; }
    /// <summary>
    /// 销售订单
    /// </summary>
    public virtual SaleOrder? Order { get; set; }
}

/// <summary>
/// 销售订单支付记录
/// </summary>
[Table("sale_order_payment_record"), DisplayName("销售订单支付记录")]
public abstract class SaleOrderPaymentRecord<TKey> : AccountRecord<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey> where TKey : IConvertible { }